package com.shan;

import java.util.Random;

/**
 * @Author: ShanYuqing
 * @Version: v1.0
 */
public class YanZheng {
    /*
            需求：请从26个英文字母（大小写都包含），以及数字0-9中，随机生成一个5位的字符串验证码并打印在控制台
            效果：uYasd 3h6h7

            注意事项：打印字符型数组名，不会看到地址值，而是元素的内容
     */
    public static void main(String[] args) {
        char[] crs = getChars();

        yanzheng555(crs);
    }

    private static void yanzheng555(char[] crs) {
        Random r = new Random();
        String check = "";
        for (int i = 0; i < 5; i++) {
            int randomIndex = r.nextInt(crs.length);
            check+= crs[randomIndex];
        }
        System.out.println(check);
    }

    private static char[] getChars() {
        char[] crs = new char[26 + 26 + 10];
        int index = 0;
        for (char c = 'a'; c <= 'z';c++){
            crs[index] = c;
            index++;
        }
        for(char c = 'A';c<='Z';c++){
            crs[index] = c;
            index++;
        }
        for(char c ='0';c<='9';c++)
        {
            crs[index] = c;
            index++;
        }
//        System.out.println(crs);
        return crs;
    }
}
